<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:of="http://omnifaces.org/functions"
	template="/WEB-INF/templates/template.xhtml">
	
<ui:define name="headIncludes">
	<f:event listener="#{vendaBean.initializeDetail(param.numNota, param.numSerie)}" type="preRenderView"/>
	
	<style>
		.panel300 {
			width: 300px;
		}
		.panel120 {
			width: 120px;
		}
		.panel80 {
			width: 80px;
		}
	</style>
</ui:define>
	
	<ui:define name="pageName">Detalhe de Venda</ui:define>
	
	<ui:define name="buttons">
		<p:commandButton value="Cancelar venda" style="height:28px;" action="#{vendaBean.openDialogConfirmCancel}" process="@this" rendered="#{vendaBean.currentVenda.status != 'CANCELADA'}" id="btCancelar" icon="ui-icon-cancel"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{vendaBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>
	</ui:define>
	
	<ui:define name="content">
		<p:panel>
			<div>
				<p:messages autoUpdate="true" closable="true"/>
				<h:panelGrid columns="1" id="panelStatus">
					<h:outputText style="font-weight:bold;padding:7px;" value="Status da venda: #{vendaBean.currentVenda.status}" rendered="#{vendaBean.currentVenda.status == 'CANCELADA'}"/>				
				</h:panelGrid>
				<h:panelGrid columns="4" style="padding:5px;" id="panel1"  columnClasses="panel120, panel80, panel300">
					<h:outputText style="font-weight:bold;padding:7px;" value="Numero da nota" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Série" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Cliente" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Data de emissão" />
					
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.numeroNota}"/>
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.numeroSerie}"/>
					<h:outputText style="padding:7px;" value="#{of:abbreviate(vendaBean.currentVenda.cliente.nome, 60)}"/>
			
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.emissao}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
				</h:panelGrid>
								
				<div style="padding-top:10px; margin-left: 10px;">
					<p:dataTable emptyMessage="Não há registros"
						id="tableItensVenda" value="#{vendaBean.currentVenda.itensVenda}"
						var="item">						
						<p:columnGroup type="header">  
				            <p:row>
				            	<p:column rowspan="2" headerText="Código" width="25"/>			 
								<p:column rowspan="2" headerText="Produto"/> 
								<p:column rowspan="2" headerText="Qtde." width="40"/>
								<p:column rowspan="2" headerText="V. unit." width="50"/>
								<p:column rowspan="2" headerText="V. total" width="50"/>
								<p:column rowspan="2" headerText="BC ICMS" width="40"/>
								<p:column rowspan="2" headerText="V. ICMS" width="40"/>
								<p:column rowspan="2" headerText="V. IPI" width="40"/>
				                <p:column colspan="1" headerText="Alíquota" /> 
				            </p:row>  
				  
				            <p:row>  
				                <p:column headerText="ICMS" width="20"/>  
				            </p:row>  
				        </p:columnGroup>
				        
		            	<p:column style="text-align:center;">  
					    	#{item.produto.id} 
						</p:column>				 
						<p:column>  
					    	#{item.produto.descricao}  
						</p:column> 
						<p:column style="text-align:center;">  
					    	#{item.quantidade}  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valor}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText> 
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.total}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.bcIcms}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valorIcms}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
					
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valorIcms}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.percentualIcms}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
				  	</p:dataTable>
				</div>
				
				<h:panelGrid columns="6" style="padding:5px;" id="panelTotal">
					<h:outputText style="font-weight:bold;padding:7px;" value="BC ICMS"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor ICMS"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Total dos produtos"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Desconto (%)"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Desconto (R$)"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Total da nota"/>
						
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.bcIcms}" id="outputBcIcms">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.valorIcms}" id="outputValorIcms">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
								
					<h:outputText style="padding:7px;" value="#{vendaBean.totalItensNota}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.descontoPercentual}">
						<f:convertNumber pattern="#,###,##0.00" />
					</h:outputText>
					
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.descontoValor}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.totalNota}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
				</h:panelGrid>
				
				<h:panelGrid columns="1" style="padding:5px;">
					<h:outputText style="font-weight:bold;padding:7px;" value="Condição de pagamento"/>
									
					<h:outputText style="padding:7px;" value="#{vendaBean.currentVenda.condicaoPagamento.condicaoPagamento}"/>
				</h:panelGrid>
				
				<div style="padding-top:10px; margin-left: 10px;">
					<p:dataTable emptyMessage="Não há registros" style="width:500px;" value="#{vendaBean.contasReceber}" 
						var="conta" rowIndexVar="index" id="tableContasReceber">						
						<p:column headerText="Parcela" style="width:100px; text-align:center;">  
					    	<h:outputText value="#{index + 1}"/>  
						</p:column>				 
						<p:column headerText="Vencimento" style="width:100px; text-align:center;">  
					    	<h:outputText value="#{conta.dataVencimento}">
								<f:convertDateTime pattern="dd/MM/yyyy"/>
							</h:outputText>  
						</p:column> 
						<p:column headerText="Valor" style="width:100px; text-align:center;">  
					    	<h:outputText value="#{conta.valor}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText>   
						</p:column>
						
						<p:column headerText="Status" width="60" style="text-align:center;">
							<h:outputText value="#{conta.status}"/>
						</p:column>
				  	</p:dataTable>
				</div>
			</div>
		</p:panel>				
	</ui:define>
	<ui:define name="popups">
		<p:dialog appendToBody="true" modal="true" closable="false" widgetVar="popupConfirmCancel"
			width="340" resizable="false" header="Confirmação" height="75">
			<h:form>
				<div style="margin-top: 10px;">
					<h:outputText value="Confirma o cancelamento da venda?"/>
				</div>
				<div align="right" style="margin-top: 15px;">
					<p:commandButton value="Confirmar" actionListener="#{vendaBean.cancelarVenda}" oncomplete="popupConfirmCancel.hide()" icon="ui-icon-check"/>
					<p:commandButton value="Cancelar" onclick="popupConfirmCancel.hide()" icon="ui-icon-cancel"/>
				</div>		
			</h:form>			
		</p:dialog>
	</ui:define>
</ui:composition>